<?php 
/**
 * 前台列表页控制器
 */
class ListController extends CommonController{
    private $model;
    function __init(){
        $this->model = K('Category');
    }
	public function index(){
		// 共用导航分类
    	$this->category();
        $cid = Q('get.cid',0,'intval');
        // p($cid);
        // 当前分类位置
        $path = $this->path($cid);
        ksort($path);
        $this->assign('path',$path);
        // 云台热卖
        $this->hot();
        //通过cid获得所有商品ID
        $gids = $this->model->get_gid($cid);
        // p($gids);
        // 如果分类下有商品
        if ($gids) {
            // 通过gid查商品属性表
            $attr = K('GoodsAttr')->get_attr($gids);
            // p($attr);
            $this->assign('g_attr',$attr);
            // 筛选参数
            $total = count($attr);
            $param = isset($_GET['param']) ? explode('_',$_GET['param']) : array_fill(0,$total,0);
            // 防止用户乱改param(参数)
            if (count($param) != $total) {
                $param = array_fill(0,$total,0);
            }
            $this->assign('param',$param);
            // 通过得到$param进行筛选
            $last_gids = k('GoodsAttr')->filter_gids($param,$gids);

        }else{
            // 如果分类没有商品
            $last_gids = array();
        }
        // p($last_gids);
        $count = count($last_gids);
        $count_data = M('category')->where("cid='{$cid}'")->getField('cname',true);
        $count_data[] = $count;

        // p($c_data);
        $this->assign('count_data',$count_data);


        // 商品展示
        $this->assign('g_data',$this->model->get_goods($cid,$last_gids));

		$this->display();
	}









	
}
















 ?>